package com.example.dnm.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.dnm.dao.RoleDao;
import com.example.dnm.pojo.Role;
import com.example.dnm.service.RoleService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleServiceImpl implements RoleService {
    @Autowired
    private RoleDao roleDao;
    @Override
    public List<Role> findAllRole(Role role) {
        if(role.getPage()!=null&&role.getSize()!=null)
        {
            PageHelper.startPage(role.getPage(),role.getSize());
        }
        QueryWrapper<Role> roleQueryWrapper = new QueryWrapper<>();
        List<Role> list=roleDao.selectList(roleQueryWrapper);
        return list;
    }

    @Override
    public Role findRoleByName(Role role) {
        return roleDao.selectOne(new QueryWrapper<Role>().eq("rolename",role.getRolename()));
    }

    @Override
    public int addRole(Role role) {
        return roleDao.insert(role);
    }

    @Override
    public int editRole(Role role) {
        return roleDao.updateById(role);
    }

    @Override
    public int deleteRole(Role role) {
        return roleDao.deleteById(role.getId());
    }
}
